package com.j2eefast.flowable.bpm.service;


import cn.hutool.core.util.IdUtil;
import com.j2eefast.flowable.bpm.entity.bpmCrmEndorderEntity;
import com.j2eefast.flowable.bpm.mapper.bpmCrmEndorderMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 结束订单Service接口
 * @author: yhli
 * @date 2020-06-28 21:09
 */
@Service
public class bpmCrmEndorderService extends ServiceImpl<bpmCrmEndorderMapper,bpmCrmEndorderEntity> {

	@Resource
	private bpmCrmEndorderMapper bpmCrmEndorderMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<bpmCrmEndorderEntity> queryWrapper = new QueryWrapper<bpmCrmEndorderEntity>();
              String saleCode = (String) params.get("saleCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleCode), "sale_code", saleCode);
                               String saleUserid = (String) params.get("saleUserid");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleUserid), "sale_userid", saleUserid);
          String outCarVin = (String) params.get("outCarVin");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVin), "out_car_vin", outCarVin);
          String outCarVehicle = (String) params.get("outCarVehicle");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVehicle), "out_car_vehicle", outCarVehicle);
          String orderEndType = (String) params.get("orderEndType");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderEndType), "order_end_type", orderEndType);
             String creditRealitySum = (String) params.get("creditRealitySum");
         queryWrapper.eq(ToolUtil.isNotEmpty(creditRealitySum), "credit_reality_sum", creditRealitySum);
          String creditBillFilepath = (String) params.get("creditBillFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(creditBillFilepath), "credit_bill_filepath", creditBillFilepath);
          String costType = (String) params.get("costType");
         queryWrapper.eq(ToolUtil.isNotEmpty(costType), "cost_type", costType);
          String costAmount = (String) params.get("costAmount");
         queryWrapper.eq(ToolUtil.isNotEmpty(costAmount), "cost_amount", costAmount);
          String costAllBusinessFilepath = (String) params.get("costAllBusinessFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(costAllBusinessFilepath), "cost_all_business_filepath", costAllBusinessFilepath);
          String commissionRealitySum = (String) params.get("commissionRealitySum");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionRealitySum), "commission_reality_sum", commissionRealitySum);
          String commissionCurrentCost = (String) params.get("commissionCurrentCost");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionCurrentCost), "commission_current_cost", commissionCurrentCost);
          String commissionFinalProfit = (String) params.get("commissionFinalProfit");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionFinalProfit), "commission_final_profit", commissionFinalProfit);
          String commissionFinalAchievement = (String) params.get("commissionFinalAchievement");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionFinalAchievement), "commission_final_achievement", commissionFinalAchievement);
          String commissionPercentage = (String) params.get("commissionPercentage");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionPercentage), "commission_percentage", commissionPercentage);
          String commissionFinalCommission = (String) params.get("commissionFinalCommission");
         queryWrapper.eq(ToolUtil.isNotEmpty(commissionFinalCommission), "commission_final_commission", commissionFinalCommission);
          String approvalSalesDirector = (String) params.get("approvalSalesDirector");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalSalesDirector), "approval_sales_director", approvalSalesDirector);
             String approvalReconditioning = (String) params.get("approvalReconditioning");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalReconditioning), "approval_reconditioning", approvalReconditioning);
             String approvalMaintenanceCenter = (String) params.get("approvalMaintenanceCenter");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalMaintenanceCenter), "approval_maintenance_center", approvalMaintenanceCenter);
             String approvalTransport = (String) params.get("approvalTransport");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalTransport), "approval_transport", approvalTransport);
             String approvalCashier = (String) params.get("approvalCashier");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalCashier), "approval_cashier", approvalCashier);
             String approvalInventory = (String) params.get("approvalInventory");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalInventory), "approval_inventory", approvalInventory);
             String approvalTax = (String) params.get("approvalTax");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalTax), "approval_tax", approvalTax);
             String approvalAccounting = (String) params.get("approvalAccounting");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalAccounting), "approval_accounting", approvalAccounting);
             String approvalSalesDirectorReview = (String) params.get("approvalSalesDirectorReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(approvalSalesDirectorReview), "approval_sales_director_review", approvalSalesDirectorReview);
     		Page<bpmCrmEndorderEntity> page = bpmCrmEndorderMapper.selectPage(new Query<bpmCrmEndorderEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params,bpmCrmEndorderEntity bpmCrmEndorderEntity) {
		Page<bpmCrmEndorderEntity> page = bpmCrmEndorderMapper.findPage(new Query<bpmCrmEndorderEntity>(params).getPage(), bpmCrmEndorderEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="FLOWABLE")
	@Transactional(rollbackFor = Exception.class)
	public boolean deletebpmCrmEndorderByIds(String[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="FLOWABLE")
	public boolean deletebpmCrmEndorderById(String id) {
		return removeById(id);
	}

	/**
     * 保存
     */
    @DataSource(name="FLOWABLE")
	public boolean savebpmCrmEndorder(bpmCrmEndorderEntity bpmCrmEndorder){
        bpmCrmEndorder.setId(IdUtil.fastSimpleUUID());
        return save(bpmCrmEndorder);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="FLOWABLE")
	public boolean updatebpmCrmEndorderById(bpmCrmEndorderEntity bpmCrmEndorder) {
		return updateById(bpmCrmEndorder);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="FLOWABLE")
	public bpmCrmEndorderEntity getbpmCrmEndorderById(String id){
		return getById(id);
	}
}
